package com.yushealth.prostate.fingerdanceforprostate;


import android.app.DialogFragment;
import android.app.Fragment;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


/**
 * A simple {@link Fragment} subclass.
 */
public class AlarmPopupFragment extends DialogFragment {

    Ringtone ringtone;
    TextView message;

    public static AlarmPopupFragment newInstance(String title) {
        AlarmPopupFragment frag = new AlarmPopupFragment();
        Bundle args = new Bundle();
        args.putString("title", title);
        frag.setArguments(args);
        return frag;
    }

    public AlarmPopupFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_alarm_popup, container, false);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        message = (TextView)getActivity().findViewById(R.id.message);
        message.setText(getArguments().getString("title"));
        // 播放声音
        Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        if (alarmUri == null) {
            alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        }
        ringtone = RingtoneManager.getRingtone(getActivity().getApplication(), alarmUri);
        ringtone.play();
    }

    public void btnOkClick(View view) {
        ringtone.stop();
        dismiss();
    }
}
